# Post-upgrade scripts

#REGION functions

function Display-StartPost(){

Write-Host "##########################################"
Write-Host "# SharePoint Post Started on $env:computername"
$global:starttime = Get-Date
Write-Host "# Start Time: $global:starttime"
$username = [Environment]::UserDomainName + "\" + [Environment]::UserName
Write-Host "# User: $username"
Write-Host "#"
Write-Host "#"
Write-Host "##########################################"
}

function Display-EndPost(){

Write-Host "##########################################"
Write-Host "# SharePoint Post Script Completed"
Write-Host "#"
$global:endtime = get-date
Write-Host "# End Time: $global:endtime"
$timespan = New-TimeSpan -Start $global:starttime -End $global:endtime
Write-Host "# Deployment Time: $($timespan.Hours) hours, $($timespan.Minutes) minutes, $($timespan.Seconds) seconds"
Write-Host "##########################################"
$env:current = "complete"
}


function Start-Logging(){

	## Create Directory
	if (Test-Path "C:\log"){
	}else{
	New-Item -path c:\ -name log -type directory | Out-Null
	}
	
	## Create Directory based on Date
	$dateformat = get-date -format "yyyy-MM-dd"
	if (Test-Path "C:\log\$dateformat"){
	}else{
	New-Item -path c:\log -name $dateformat -type directory | Out-Null
	}
	
	$global:starttime = Get-Date
	## Start Logging
	$hourmin = get-date -format "yyyy-MM-dd-hhmm"
	Start-Transcript -Path "c:\log\$dateformat\$env:computername-$hourmin-post.rtf"
}

function Stop-Logging(){
	
	Stop-Transcript
}

#ENDREGION functions


pushd "$env:SPAutoFolder\Post"
$env:current = "post"
Display-StartPost

if ($env:logging -eq $false){
} else {
Start-Logging
}
## Services
#& .\ServiceScripts\StateService\enableStateService.ps1

## Configurations
& .\Email\set-OutgoingEmail.ps1
& .\Logging\LoggingSetup.ps1
& .\AAM\AAM.ps1
& .\permissions\addUsers-SecurityPolicy.ps1
& .\permissions\addSuperUserScript.ps1
& .\HostFile\set-HostFile.ps1
& .\webappsettings\set-WebAppSettings.ps1

popd

Display-EndPost
if ($env:logging -eq $false){
} else {
Stop-Logging
}